package com.it.travel.controller.admin;

import com.it.travel.common.RequiredPermission;
import com.it.travel.service.admin.AdminPermissionService;
import com.it.travel.vo.Params.PageParams;
import com.it.travel.vo.Params.admin.*;
import com.it.travel.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/permission")
@CrossOrigin
public class AdminPermissionController {
    @Resource
    private AdminPermissionService adminPermissionService;

//    @RequiredPermission("sys:permission:find")
    @GetMapping("")
    public Result<?> getStoryInfoPage(PageParams pageParams) {
        Result<?> result = adminPermissionService.getPermissionInfoPage(pageParams);
        return result;
    }

    @PostMapping("")
    public Result<?> save(@RequestBody AdminPermissionAddParams adminPermissionAddParams) {
        Result<?> result = adminPermissionService.save(adminPermissionAddParams);
        return result;
    }


    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable("id") Integer id) {
                System.out.println("id = " + id);

        Result<?> result = adminPermissionService.delete(id);
        return result;
//        return null;
    }

    //
    @PutMapping("")
    public Result<?> update(@RequestBody AdminPermissionUpdateParams adminPermissionUpdateParams) {
        Result<?> result = adminPermissionService.update(adminPermissionUpdateParams);
        return result;
    }

    //    //
//    @PostMapping("/deletebatch")
//    public Result<?> deletebatch(@RequestBody List<Integer> ids) {
//        Result<?> result = adminStoryService.deletebatch(ids);
//        return result;
//    }
//
//    @GetMapping("/detail/{id}")
//    public Result<?> findProductDetail(@PathVariable("id") Integer id) {
//        Result<?> result = adminStoryService.findStoryDetail(id);
//        return result;
////        return null;
//    }
    @GetMapping("/first")  // 获取一级分类
    public Result<?> findFirstName() {
        Result<?> result = adminPermissionService.findFirstName();
        return result;
    }

    @PostMapping("/first")
    public Result<?> saveFirstPermission(@RequestBody AdminPermissionAddFirstParams adminPermissionAddFirstParams) {
        System.out.println("adminPermissionAddFirstParams = " + adminPermissionAddFirstParams);
        Result<?> result = adminPermissionService.saveFirstPermission(adminPermissionAddFirstParams);
        return result;
    }

}
